﻿Public Class fTipoProducto
    Dim daTipoProd As lbGlobalcom.dsProductosTableAdapters.PRO_TIPOPRODUCTOTableAdapter
    'Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub btnCargar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargar.Click
        Try
            If DsProductos.PRO_TIPOPRODUCTO.GetChanges IsNot Nothing Then
                PRO_TIPOPRODUCTOBindingSource.EndEdit()
                If MessageBox.Show("Hay registros pendientes por salvar, desea guardarlos", "Salvar Cambios", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    PRO_TIPOPRODUCTOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
            daTipoProd.Fill(DsProductos.PRO_TIPOPRODUCTO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fTipoProducto_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If DsProductos.PRO_TIPOPRODUCTO.GetChanges IsNot Nothing Then
                PRO_TIPOPRODUCTOBindingSource.EndEdit()
                If MessageBox.Show("Hay registros pendientes por salvar, desea guardarlos", "Salvar Cambios", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    PRO_TIPOPRODUCTOBindingNavigatorSaveItem.PerformClick()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub fTipoProducto_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            'daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
            daTipoProd = New lbGlobalcom.dsProductosTableAdapters.PRO_TIPOPRODUCTOTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try

    End Sub

    Private Sub PRO_TIPOPRODUCTOBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PRO_TIPOPRODUCTOBindingNavigatorSaveItem.Click
        Try
            Validate()
            PRO_TIPOPRODUCTOBindingSource.EndEdit()
            daTipoProd.Update(DsProductos.PRO_TIPOPRODUCTO)
            MessageBox.Show("Se salvarón registros con exito", "Salvar Registros", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    'Private Sub PRO_TIPOPRODUCTODataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles PRO_TIPOPRODUCTODataGridView.CellBeginEdit
    '    Try
    '        If e.ColumnIndex = 1 AndAlso PRO_TIPOPRODUCTODataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
    '            Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
    '            dt = daClave.GetDataByIdClavePrimaria("PRO_TIPOPRODUCTO")
    '            If dt.Count Then
    '                Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
    '                dr = dt.Rows(0)
    '                Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
    '                PRO_TIPOPRODUCTODataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
    '                Cons = Nothing
    '                PRO_TIPOPRODUCTOBindingSource.EndEdit()
    '                daTipoProd.Update(DsProductos.PRO_TIPOPRODUCTO)
    '            End If
    '        End If
    '    Catch ex As Exception
    '        MessageBox.Show(ex.Message)
    '        lbGlobalcom.cError.SalvaError(ex, "Henry")
    '    End Try
    'End Sub

    Private Sub PRO_TIPOPRODUCTODataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles PRO_TIPOPRODUCTODataGridView.UserDeletedRow
        Try
            MessageBox.Show("Se elimino Tipo Producto con exito", "Elimina Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
            daTipoProd.Update(DsProductos.PRO_TIPOPRODUCTO)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try
    End Sub

    Private Sub PRO_TIPOPRODUCTODataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles PRO_TIPOPRODUCTODataGridView.UserDeletingRow
        If MessageBox.Show("esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub
End Class